package com.controller;

import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

@RestController
public class IndexController {

    @RequestMapping("/index")
    public String index()  {

        String s = null;
        System.out.println(s.length());

        return "index";
    }

    //拦截所有异常:这样写在单独的控制器不好维护
    //@ExceptionHandler(Exception.class)
    //@ExceptionHandler({ArithmeticException.class, NullPointerException.class,ArrayIndexOutOfBoundsException.class})
    public Map<String,Object> ex(Exception e){
        Map<String,Object> map = new HashMap<>();
        map.put("ex",e.getMessage());
        return map;
    }

}
